#!/usr/bin/env bash

red='\e[91m'
green='\e[92m'
yellow='\e[93m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'

sudo chmod 777 $0

#Root
[[ $(id -u) != 0 ]] && echo -e " 请使用 ${red}root ${none}用户运行 ${yellow}~(^_^) ${none}" && exit 1

#获取系统架构
sys_str=$(uname -m)
#修复系统软件标志位
software_repair_flag=0
#文件标志位
file_flag=0
#下载标志位
download_flag=''
#获取普通用户
this_user=$(users | awk '{print $1}')
#获取当前时间
timestamp=$(date +%Y-%m-%d_%H:%M:%S)
#获取系统版本
os_version=`head -n1 /etc/kylin-build |awk '{print $2}'`
os_version_small=$(cat /etc/kylin-build | grep -w "buildid" | awk -F" " '{print $2}')
#获取芯片
cpu_name=$(lscpu | grep "型号名称" | awk -F " " '{print $2}')
#获取根目录
sys_root=$(lsblk -o NAME,MOUNTPOINT -P | grep -w / | awk -F" " '{print $1}' | awk -F"=" '{print $2}' | awk -F"\"" '{print $2}')

#获取普通用户家目录
home_path() {
  cd /home/$this_user || exit
}

#暂停
get_pause() {
  SAVEDSTTY=$(stty -g)
  stty -echo
  stty cbreak
  dd if=/dev/tty bs=1 count=1 2>/dev/null
  stty -raw
  stty echo
  stty $SAVEDSTTY
}

#回到主菜单
return_menu(){
  echo
  echo
  echo -e "按任意键返回主菜单"
  char=$(get_pause)
  echo
  menu
}

#1.系统信息
system_message() {
  clear
  echo
  echo -e "$yellow 1. $cyan 按 1 查询系统信息"
  echo
  echo -e "$yellow 2. $cyan 按 2 查看实时网速"
  echo
  echo -e "$yellow 3. $cyan 按 3 备份日志到桌面"
  echo
  echo -e "$yellow 4. $cyan 按 4 查看系统运行信息"
  echo
  echo -e "$red 按 0 返回主菜单"
  echo
  read -rp "$(echo -e "$magenta 请选择数字 : $none ")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      system_info
      ;; #获取系统基本信息
    2)
      net_speed
      ;; #实时网速
    3)
      tar -czvf log_$timestamp.tar.gz /var/log
      chmod 644 log_$timestamp.tar.gz
      clear
      echo -e "$magenta 找到log_$timestamp.tar.gz这个文件，备份到桌面了，从桌面拷出来发给我$none \n"
      ;;
    4)
      date | tee -a /home/$this_user/桌面/stat_cpu_mem.txt
      echo "占用cpu最高的10个进程是:" | tee -a /home/$this_user/桌面/stat_cpu_mem.txt
      ps aux --sort=-%cpu|sed -n '1,11p' | tee -a /home/$this_user/桌面/stat_cpu_mem.txt
      echo "占用mem最高的10个进程是:" | tee -a /home/$this_user/桌面/stat_cpu_mem.txt
      ps aux --sort=-%mem|sed -n '1,11p' | tee -a /home/$this_user/桌面/stat_cpu_mem.txt
      echo "总体内存使用情况是:"  | tee -a /home/$this_user/桌面/stat_cpu_mem.txt
      free -h | tee -a /home/$this_user/桌面/stat_cpu_mem.txt
      echo "中断情况是:"  | tee -a  /home/$this_user/桌面/stat_cpu_mem.txt
      cat /proc/interrupts  | tee -a  /home/$this_user/桌面/stat_cpu_mem.txt
      echo  | tee -a  /home/$this_user/桌面/stat_cpu_mem.txt
    esac
  fi
}

#1.1 获取系统基本信息
system_info() {
  clear
  echo
  echo -e "$yellow 请稍等10秒左右$none"
  version=$(cat /etc/os-release | grep -w "VERSION" | awk -F"=" '{print $2}')                                                     #系统版本
  version_small=$(cat /etc/kylin-build | grep -w "Build" | awk -F" " '{print $2}')                                                #小版本号
  kylin_serial=$(kylin_serial)                                                                                                    #服务序列号
  kyactivation_key=$(cat /etc/.kyactivation 2>/dev/null)                                                                          #激活码
  kyregistration_key=$(kylin_gen_register)                                                                                        #注册码
  system_serial_number=$(cat /sys/class/dmi/id/product_serial)                                                                    #主机序列号
  blk_serials=$(lsblk -d -o NAME,SERIAL,TYPE -P | grep disk)                                                                      #硬盘序列号
  phy_adapters=$(ls /sys/class/net/ | grep -v "$(ls /sys/devices/virtual/net/)")                                                  #网卡
  echo -e "电脑cpu为: $cpu_name"
  echo -e "操作系统版本为: $version"
  echo -e "操作系统小版本号为: $version_small"
  echo -e "服务序列号为：$kylin_serial"
  echo -e "激活码为: $kyactivation_key"
  echo -e "注册码: $kyregistration_key"
  echo -e "主机序列号: $system_serial_number"
  echo -e "硬盘序列号: $blk_serials"
  echo -e "网卡MAC地址:"
  for phy_adapter in $phy_adapters; do
    mac=$(cat /sys/class/net/$phy_adapter/address)
    echo "NAME=\"$phy_adapter\" MAC=\"$mac\""
  done
  echo -e "根目录为：$sys_root"
  return_menu
}

#1.2 实时网速
net_speed() {
  #NIC=$1
  echo -e " In ------ Out"
  while true; do
    #awk '$0~"'$NIC'"{print $2}' /proc/net/dev | awk 'NR==8{print $1}'
    OLD_IN=$(awk '{print $2}' /proc/net/dev | awk 'NR==8{print $1}')
    OLD_OUT=$(awk '{print $10}' /proc/net/dev | awk 'NR==8{print $1}')
    sleep 1
    NEW_IN=$(awk '{print $2}' /proc/net/dev | awk 'NR==8{print $1}')
    NEW_OUT=$(awk '{print $10}' /proc/net/dev | awk 'NR==8{print $1}')
    IN=$(printf "%.1f%s" "$((($NEW_IN-$OLD_IN)/1024))" "KB/s")
    OUT=$(printf "%.1f%s" "$((($NEW_OUT-$OLD_OUT)/1024))" "KB/s")
    echo "$IN $OUT"
    sleep 1
  done
}

#2.部分系统bug修复
system_repair() {
  clear
  echo
  echo -e "$yellow 1. $cyan 按 1 系统激活相关问题--如激活时不出现二维码等问题"
  echo
  echo -e "$yellow 2. $cyan 按 2 尝试修复系统任务栏消失---修改分辨率后仍旧不出现"
  echo
  echo -e "$yellow 3. $cyan 按 3 桌面右下角不显示小键盘图标，且调不出输入法"
  echo
  echo -e "$yellow 4. $cyan 按 4 开机后桌面图标无显示，或显示正在启动caja，只有任务栏"
  echo
  echo -e "$yellow 5. $cyan 按 5 开机进命令行不进桌面"
  echo
  echo -e "$yellow 6. $cyan 按 6 清理垃圾--输入密码进不去桌面跳回登录页面（磁盘数据满，尝试清除部分数据）"
  echo
  echo -e "$yellow 7. $cyan 按 7 桌面密钥环清除"
  echo
  echo -e "$yellow 8. $cyan 按 8 ll查看命令不生效--误删.bashrc和.bash_profile文件"
  echo
  echo -e "$yellow 9. $cyan 按 9 控制面板打不开,如果还报错,执行10"
  echo
  echo -e "$yellow 10. $cyan 按 10 重装卸载残留的文件--注意重要文件要做备份，适用于安装或卸载软件导致系统出问题--比如9中控制面板打开报错等"
  echo
  echo -e "$yellow 11. $cyan 按 11 关机卡麒麟软件四个字"
  echo -e "特定情况出现：如安装身份鉴别等软件出现问题--lightdm报错缺pam_gnome_keyring.so\pam_kwallet.so\pam_kwallet.so错误"
  echo
  echo -e "$yellow 12. $cyan 按 12 老版本尝试增加exfat硬盘支持"
  echo
  echo -e "$yellow 13. $cyan 按 13 触摸板滑动方向改为windows一致"
  echo
  echo -e "$yellow 14. $cyan 按 14 增加rc.local"
  echo
  echo -e "$yellow 15. $cyan 按 15 在开发盘下尝试fsck修复根目录"
  echo
  echo -e "$yellow 16. $cyan 按 16 在开发盘下挂载固态盘"
  echo
  echo -e "$red 按 0 返回主菜单"
  echo
  read -rp "$(echo -e "$magenta 请选择数字 : $none ")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      #系统激活相关
      activation
      ;;
    2)
      #系统任务栏消失
      home_path
      sudo rm -rf .cache/ .config/ .Xauthority
      ;;
    3)
      #右下角无小键盘及输入法
      home_path
      sudo rm -rf .config/
      sudo systemctl restart lightdm
      ;;
    4)
      #开机桌面图标无显示
      sudo apt update
      sudo rm -rf .config/
      sudo apt install caja --reinstall
      ;;
    5)
      #开机进tty1-桌面caja有问题--重装caja和重装重置lightdm
      sudo apt update
      sudo apt install caja --reinstall
      sudo apt install lightdm --reinstall
      sudo dpkg-reconfigure lightdm
      systemctl enable lightdm
      ;;
    6)
      #清理垃圾
      sudo apt clean
      sudo apt autoclean                                                #删/var/cache/apt/archives下deb文件
      sudo apt autoremove                                               #删不需要的依赖
      dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo dpkg --purge #删软件残留配置--rc开头的文件
      sudo rm -rf /tmp/*                                                #删tmp缓存
      ;;
    7)
      #桌面密钥环消除
      sudo apt install seahorse -y
      echo
      echo
      echo -e "$red 三秒后在打开的界面右键点密码下的key，删除即可$none"
      echo
      echo
      sleep 3
      sudo seahorse
      ;;
    8)
      #ll不生效
      home_path
      sudo cp /etc/skel/.bashrc ./
      sudo chmod 644 .bashrc
      touch .bash_profile
      echo -e "if [ -f ~/.bashrc ]; then\n\t. ~/.bashrc\nfi" >.bash_profile
      ;;
    9)
      #控制面板打不开
      sudo apt install kylin-control-center --reinstall
      kylin-control-center
      ;;
    10)
      #重装卸载残留的文件--适用于安装或卸载软件导致系统出问题
      sudo dpkg -P upstart
      sudo dpkg -P firefox
      sudo apt install aptitude
      dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo aptitude install -y
      ;;
    11)
      #无法关机
      sed -i  "/keyring/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm
      sed -i  "/kwallet/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm
      sed -i  "/keyring/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm-greeter
      sed -i  "/kwallet/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm-greeter
      ;;
    12)
      sudo apt install exfat-fuse exfat-utils
      ;;
    13)
      sudo synclient VertScrollDelta=-30
      ;;
    14)
      #增加rc.local
      echo -e "\n[Install]\nWantedBy=multi-user.target\n" >> /lib/systemd/system/rc-local.service
      touch /etc/rc.local && chmod 755 /etc/rc.local
      echo -e "#!/bin/bash\n" >> /etc/rc.local
      systemctl start rc-local.service
      systemctl enable rc-local.service
      echo -e "接下来可以自己编辑vim /etc/rc.local添加开机启动项了。"
      ;;
    15)
      #在开发盘下尝试fsck修复根目录
      fsck -y /dev/nvme0n1p2
      ;;
    16)
      #在开发盘下挂载固态盘
      mkdir -p /disk01
      chmod -R 777 /disk01
      mount /dev/nvme0n1p2 /disk01
      echo -e "打开文件系统下disk01文件夹查看"
      ;;
    esac
  fi
}

#3.1 系统激活相关
activation() {
  clear
  echo -e "$yellow 1. $yellow 按 1 修复激活时提示无效序列号--下载对应系统版本的kyinfo文件"
  echo
  echo -e "$yellow 2. $yellow 按 2 修复激活时提示无法获取硬件信息错误码0017问题"
  echo
  echo -e "$yellow 3. $yellow 按 3 查看系统版本"
  echo
  echo -e "$yellow 4. $yellow 按 4 查看系统注册码"
  echo
  echo -e "$yellow 5. $yellow 按 5 查询序列号"
  echo
  echo -e "$yellow 6. $yellow 按 6 查看系统激活码"
  echo
  echo -e "$yellow 7. $yellow 按 7 命令交互式激活操作系统$none"
  echo
  echo -e "$red 按 0 返回主菜单$none"
  echo
  read -rp "$(echo -e "$magenta 请选择相应数字:$none")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      activationdownload
      act_flag='activation'
      ;;
    2)
      rm -rf /etc/.kyhwid
      kylin_activation_check
      ;;
    3)
      cat /etc/kylin-build
      ;;
    4)
      sudo kylin_gen_register
      ;;
    5)
      sudo cat /etc/.kyinfo
      ;;
    6)
      sudo cat /etc/.kyactivation
      ;;
    7)
      kylin-system-verify
      ;;
    esac
  fi
}

activationdownload() {
  clear
  echo
  echo -e "-----先看看电脑时间对不对，不对的话继续----"
  echo
  echo -e "$yellow 选 1 安装V10-0710版本 $none"
  echo
  echo -e "$yellow 选 2 安装V10-1026版本 $none"
  echo
  echo -e "$yellow 选 3 安装V10-0710-2版本 $none"
  echo
  echo -e "$yellow 选 4 安装V10-1026-2版本 $none"
  echo
  echo -e "$yellow 选 5 安装V10-2107版本 $none"
  echo
  echo -e "$yellow 选 6 安装V10-2203版本 $none"
  echo
  echo -e "$yellow 选 7 安装V10SP1-2107版本 $none"
  echo
  echo -e "$yellow 选 8 安装V10SP1-2203版本 $none"
  echo
  echo -e "$red 按 0 返回主菜单$none"
  echo
  read -rp "$(echo -e "$magenta 请选择数字: $none")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      download_flag='act_v10_0710'
      download_zip
      ;;
    2)
      download_flag='act_v10_1026'
      download_zip
      ;;
    3)
      download_flag='act_v10_0710_2'
      download_zip
      ;;
    4)
      download_flag='act_v10_1026_2'
      download_zip
      ;;
    5)
      download_flag='act_v10_2107'
      download_zip
      ;;
    6)
      download_flag='act_v10_2203'
      download_zip
      ;;
    7)
      download_flag='act_v10sp1_2107'
      download_zip
      ;;
    8)
      download_flag='act_v10sp1_2203'
      download_zip
      ;;
    esac
  fi
}

#TODU
act_dw_auto() {
  clear
  act_flag='activation' 
  if [ $os_version == "V10"];then
    if [ $os_version_small == "0710" ];then
      download_flag='act_v10_0710'
    elif [ $os_version_small == "0710_2" ];then
      download_flag='act_v10_0710_2'
    elif [ $os_version_small == "1026" ];then
      download_flag='act_v10_1026'
    elif [ $os_version_small == "1026_2" ];then
      download_flag='act_v10_1026_2'
    elif [ $os_version_small == "2107" ];then
      download_flag='act_v10_2107'
    elif [ $os_version_small == "2203" ];then
      download_flag='act_v10_2203'
    fi
  elif [ $os_version == "V10-SP1" ]; then
    if [ $os_version_small == "2107" ];then
      download_flag='act_v10sp1_2107'
    elif [ $os_version_small == "31950" ];then
      download_flag='act_v10sp1_2203'
    fi
  else
    echo -e "待整理"
  fi
  download_zip
}

#3.源与商店更新及修复
software_repair() {
  clear
  echo
  echo -e "$yellow 1. $cyan 按 1 修复系统更新系统源---如商店里软件较少"
  echo
  echo -e "$yellow 2. $cyan 按 2 更新源时提示GPG错误"
  echo
  echo -e "$yellow 3. $cyan 按 3 更新软件源时，提示等待报头一直为0、软件源无法加锁"
  echo
  echo -e "$yellow 4. $cyan 按 4 安装软件提示失败"
  echo
  echo -e "$yellow 5. $cyan 按 5 软件商店报错---如打开商店报0001-0005等代码、dbus服务异常"
  echo
  echo -e "$red 按 0 返回主菜单 $none\n"
  echo
  read -rp "$(echo -e "$magenta 请选择数字 : $none ")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      systemUpdate
      ;; #源更新
    2)
      software_repair_flag='soft_GPG'
      softcenter_repair
      ;; #源GPG错误
    3)
      software_repair_flag='soft_lock'
      softcenter_repair
      ;; #源报头为0、无法加锁
    4)
      software_repair_flag='soft_install_fail'
      softcenter_repair
      ;; #软件安装失败
    5)
      software_repair_flag='soft_wrong_code'
      softcenter_repair
      ;; #软件商店报错
    esac
  fi
}

#3.1 系统源更新
systemUpdate() {
  cp /etc/apt/sources.list /etc/apt/sources.list.bak
  clear
  echo -e "$yellow 注意自测，实在不能用了再用。 $none\n"
  echo
  echo -e "$yellow 原则上更新管理器会在开机几分钟内，顶多一小时自行向公司的源发请求更新源地址。 $none\n"
  echo
  echo -e "$yellow 1. $cyan 按 1 从公司那边更新一下源地址 $none\n"
  echo
  echo -e "$yellow 2. $cyan 按 2 备份现有源 $none\n"
  echo
  echo -e "$yellow 3. $cyan 按 3 还原刚备份的源 $none\n"
  echo
  echo -e "$yellow 4. $cyan 按 4 修复V10 $none\n"
  echo
  echo -e "$yellow 5. $cyan 按 5 修复V10-sp1 $none\n"
  echo
  echo -e "$yellow 6. $cyan 按 6 修复V10-sp1-hwe $none\n"
  echo
  echo -e "$yellow 7. $cyan 按 7 修复V10-sp1-麒麟9006c $none\n"
  echo
  echo -e "$yellow 8. $cyan 按 8 修复V10-sp1-990 $none\n"
  echo
  echo -e "$red 按 0 返回主菜单 $none\n"
  echo
  read -rp "$(echo -e "$cyan 请选择0-7:"$none)" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      kylin-source-update
      ;;
    2)
      cp /etc/apt/sources.list /etc/apt/sources.list.bak
      ;;
    3)
      cp /etc/apt/sources.list.bak /etc/apt/sources.list
      ;;
    4)
      echo -e "deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.0 main restricted universe multiverse\ndeb http://archive.kylinos.cn/kylin/partner juniper main\n" >/etc/apt/sources.list
      ;;
    5)
      echo -e "deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1 main universe multiverse restricted\ndeb http://archive.kylinos.cn/kylin/partner 10.1 main\n" >/etc/apt/sources.list
      ;;
    6)
      echo -e "deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1 main restricted universe multiverse\ndeb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1-hwe main\ndeb http://archive.kylinos.cn/kylin/partner 10.1 main\n" >/etc/apt/sources.list
      ;;
    7)
      echo -e "deb https://archive.kylinos.cn/kylin/KYLIN-ALL 10.1-kv main restricted universe multiverse\ndeb https://archive2.kylinos.cn/deb/kylin/production/PART-10_1-kirin9a0/custom/partner/10_1-kirin9a0 default all\n" >/etc/apt/sources.list
      ;;
    8)
      echo -e "deb https://archive.kylinos.cn/kylin/KYLIN-ALL 10.1-pv main restricted universe multiverse\ndeb https://archive.kylinos.cn/kylin/KYLIN-ALL 10.1 main restricted universe multiverse\n" >/etc/apt/sources.list
      ;;
    esac
  fi
  sudo apt update
}

#3.2 源、商店错误处理
softcenter_repair() {
  if [ $software_repair_flag == 'soft_GPG' ]; then
    #源GPG错误
    sudo mv /var/lib/apt/lists /var/lib/apt/list_$timestamp
    sudo mkdir -p /var/lib/apt/lists/partial
    sudo apt clean
    sudo apt update
  elif [ $software_repair_flag == 'soft_lock' ]; then
    #源报头为0
    sudo rm -rf /var/lib/apt/lists/*
    sudo apt update
  elif [ $software_repair_flag == 'soft_install_fail' ]; then
    #软件安装失败
    sudo apt install -f
    sudo apt-get update --fix-missing
    sudo apt autoremove
  elif [ $software_repair_flag == 'soft_wrong_code' ]; then
    #软件商店报错
    sudo apt update
    sudo apt install -y kylin-software-center --reinstall
    sudo rm /var/lib/dpkg/updates/*
    sudo rm -rf /var/lib/apt/lists/*
    sudo rm /var/lib/dpkg/lock
    sudo rm /var/lib/dpkg/lock-frontend
    sudo rm /var/cache/apt/archives/lock
    sudo dpkg --configure -a
    sudo apt install -f
    sudo apt update
  fi
}

#4.软件相关
software(){
  clear
  echo
  echo "..........我的电脑右键属性--FT2000属于ARM、3A4000属于mips........"
  echo
  echo -e "$yellow 1. $cyan 按 1 微信相关"
  echo
  echo -e "$yellow 2. $cyan 按 2 远程"
  echo
  echo -e "$yellow 3. $cyan 按 3 字体安装"
  echo
  echo -e "$yellow 4. $cyan 按 4 金山WPS-清理金山缓存"
  echo
  echo -e "$yellow 5. $cyan 按 5 试用性-crossover试用增加"
  echo
  echo -e "$yellow 6. $cyan 按 6 下载腾讯会议"
  echo
  echo -e "$yellow 7. $cyan 按 7 下载新版linuxqq"
  echo
  echo -e "$yellow 8. $cyan 按 8 2203系统，刻录软件续刻时报错"
  echo
  read -rp "$(echo -e "$magenta 请选择数字:"$none)" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      #微信相关处理
      wechat
      ;;
    2)
      #远程安装
      remote
      ;;
    3)
      #字体安装
      fonts
      ;;
    4)
      #删金山缓存
      quickstartoffice stop
      home_path
      rm -rf .config/Kingsoft
      rm -rf .local/share/Kingsoft
      quickstartoffice start
      return_menu
      ;;
    5)
      #crossover尝试增加试用
      home_path
      cd .cxoffice/
      find . -name ".eval" -exec rm -f {} \;
      sudo rm -f {}
      return_menu
      ;;
    6)
      #下载腾讯会议
      download_flag='tencent_metting'
      download_deb
      ;;
    7)
      #下载新版linuxqq
      download_flag='tencent_linuxqq'
      download_deb
      ;;
    8)
      #续刻
      download_flag='kelu_xuke'
      download_zip
      ;;
    esac
  fi
}


#4.1 微信相关问题
wechat() {
  clear
  echo
  echo "..........我的电脑右键属性--FT2000属于ARM、3A4000属于mips........"
  echo
  echo -e "$yellow 1. 按 1 在公司源中安装微信--首选"
  echo
  echo -e "$yellow 2. 按 2 Mips--微信禁用gpu--适用于微信闪退及卡顿。"
  echo
  echo -e "$yellow 3. 按 3 Mips--微信登录提示登录失败error--在公司源中修复微信相关依赖"
  echo
  echo -e "$yellow 4. 按 4 Mips--离线修复微信相关依赖---公司源不可用情况下使用"
  echo
  echo -e "$yellow 5. 按 5 无法扫码--离线安装微信2.1.4-1版本。"
  echo
  echo -e "$yellow 6. 按 6 杀微信进程--双击微信图标无反应可尝试"
  echo
  echo -e "$red 按 0 返回主菜单$none"
  echo
  read -rp "$(echo -e "$magenta 请选择数字:"$none)" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      sudo apt update
      if [ $sys_str == "mips64" ]; then
        sudo apt install -y kylin-activation libkylin-activation wechat
      else
        sudo apt install -y weixin
      fi
      ;;
    2)
      cp /usr/share/applications/wechat.desktop /usr/share/applications/wechat.desktop_$timestamp
      sed -i 's/Exec=wechat %U/Exec=wechat  --disable-gpu  %U/' /usr/share/applications/wechat.desktop
      sed -i 's/Exec=wechat %U/Exec=wechat  --disable-gpu  %U/' /home/$this_user/桌面/wechat.desktop
      echo -e "请关闭微信并重新打开微信。$none \n"
      ;;
    3)
      sudo apt update
      sudo apt install -y kylin-activation libkylin-activation
      ;;
    4)
      download_flag='wx_mips_depend'
      download_zip
      ;;
    5)
      sudo apt update
      download_flag='wx_2.1.4'
      download_deb
      ;;
    6)
      sudo killall -9 weixin
      ;;
    esac
  fi
}

#4.2 远程相关下载
remote() {
  clear
  echo
  echo -e "$red 注意有时这些软件第一次打开有时连不上，需要右下角退出重新打开一遍"
  echo
  echo -e "$yellow 1. $cyan 按 1 公司源中安装向日葵--首选"
  echo
  echo -e "$yellow 2. $cyan 按 2 安装Todesk的x86和arm版---此软件无mips"
  echo
  echo -e "$yellow 3. $cyan 按 3 离线安装向日葵"
  echo
  echo -e "$red 按 0 返回主菜单$none"
  echo
  read -rp "$(echo -e "$magenta 请选择 1 或 2 : $none")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      sudo apt install sunlogin
      ;;
    2)
      download_flag='todesk'
      download_deb
      ;;
    3)
      download_flag='sunlogin'
      download_deb
      ;;
    esac
  fi
}


#4.3 字体安装
fonts() {
  clear
  echo -e "$yellow 1. $cyan 按 1 进行批量安装，需将ttf文件拷到新建的文件夹下再继续执行"
  echo
  echo -e "$yellow 2. $cyan 按 2 安装公司开发的字体管理器，使用方法:双击ttf文件右上角有安装，适用于单个ttf安装及客户自行安装字体。"
  echo
  echo -e "$red 按 0 返回主菜单$none"
  echo
  read -rp "$(echo -e "$magenta 请选择 1 或 2 : $none")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      fontsowninstall
      ;;
    2)
      download_flag='dfonts'
      download_deb
      ;;
    esac
  fi
}

#4.3.1 字体文件批量安装
fontsowninstall() {
  mkdir newfonts
  mkdir -p /usr/share/fonts/newfonts
  chmod -R 777 ./newfonts/

  clear
  echo
  echo -e "$magenta 请将ttf字体文件拷到newfonts文件夹中再按任意键继续进行操作:"
  char=$(get_pause)
  echo
  chmod -R 777 ./newfonts/
  cp ./newfonts/* /usr/share/fonts/newfonts/
  chmod -R 777 /usr/share/fonts/newfonts/
  fc-cache /usr/share/fonts/newfonts/
  ls /usr/share/fonts/newfonts/
  echo -e "$red 应该可以用了，重新打开wps，fc相关组件未安装的需要重启下电脑。$none \n"
}

#5.文件查找
find_files() {
  clear
  echo -e "$yellow 1. $cyan 按 1 按名称查找文件(区分大小写)"
  echo
  echo -e "$yellow 2. $cyan 按 2 按名称查找文件(不区分大小写)"
  echo
  echo -e "$yellow 3. $cyan 按 3 按文件内容查找(只在home和data目录下查找--原则上用户数据都在这俩目录)"
  echo
  echo -e "$yellow 4. $cyan 按 4 按文件内容查找(自定义目录)"
  echo
  echo -e "$yellow 5. $cyan 按 5 查找源里的软件包"
  echo
  echo -e "$yellow 6. $cyan 按 6 查找本机所有安装的软件包"
  echo
  echo -e "$yellow 7. $cyan 按 7 查找本机是否安装软件包--如输入linuxqq看有没有安装qq"
  echo
  echo -e "$red 按 0 返回主菜单$none"
  echo
  echo -e "$yellow 查找的文件名或路径名保存在本目录下的find开头的txt文件中"
  echo
  read -rp "$(echo -e "$magenta 请选择数字 : $none ")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      file_flag='file_case'
      findname
      ;;
    2)
      file_flag='file_nocase'
      findname
      ;;
    3)
      file_flag='file_content'
      findname
      ;;
    4)
      file_flag='file_own_content'
      findname
      ;;
    5)
      file_flag='soft_source'
      findname
      ;;
    6)
      file_flag='soft_local_all'
      findname
      ;;
    7)
      file_flag='soft_local'
      findname
      ;;
    esac
  fi
}

findname() {
  if [ $file_flag == 'file_case' ]; then
    read -rp "$(echo -e "请输入要查找的文件名:")" name
    find /home/ -name "$name*" -print | tee find$name.txt
    return_menu
  elif [ $file_flag == 'file_nocase' ]; then
    read -rp "$(echo -e "请输入要查找的文件名:")" name
    find /home/ -iname "$name*" -print | tee find$name.txt
    return_menu
  elif [ $file_flag == 'file_content' ]; then
    read -rp "$(echo -e "请输入要查找的内容:")" content
    grep -rl "$content" /home /data | tee find$content.txt
    return_menu
  elif [ $file_flag == 'file_own_content' ]; then
    read -rp "$(echo -e "请输入要查找的内容:")" content
    read -rp "$(echo -e "请输入要查找的位置，多个位置用空格隔开:")" loc
    grep -rl "$content" $loc | tee find$content.txt
    return_menu
  elif [ $file_flag == 'soft_source' ]; then
    read -rp "$(echo -e "请输入要查找的内容:")" soft_source
    apt search $soft_source
    return_menu
  elif [ $file_flag == 'soft_local_all' ]; then
    echo -e "安装的软件包输出到文件中"
    dpkg --get-selections | tee installsoftware.txt
    return_menu
  elif [ $file_flag == 'soft_local' ]; then
    read -rp "$(echo -e "请输入要查找的内容:")" soft_local
    dpkg --get-selections | grep $soft_local
    return_menu
  fi
}

#6.打印机驱动安装

install_cups(){
  clear
  echo
  echo
  echo -e "$red 此处安装什么驱动需咨询麒麟员工"
  echo
  echo -e "$red 驱动去麒麟官网查https://eco.kylinos.cn/zoology/commercial.html?system_class=1"  
  echo
  sleep 3
  echo
  echo
  echo -e "$yellow 1. $cyan 按 1 安装惠普3.16.3"
  echo
  echo -e "$yellow 2. $cyan 按 2 安装惠普3.22.x最新版"
  echo
  echo -e "$red 按 0 返回主菜单$none"
  echo
  echo
  read -rp "$(echo -e "$magenta 请选择数字 : $none ")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      sudo apt install hp-printer-hplip-3.16.3
      ;;
    2)
      sudo apt install hplip
      ;;
    esac
  fi
}

#7.上传到ftp
up_to_ftp(){
  clear
  echo
  echo
	echo -e "${cyan} 本脚本作用：${red}查找数据盘和/home/文件夹下某时间段修改过的文件并打包"
	echo
	echo -e "${cyan} 注意：${red}比如2021年创建的，但是2022年修改过的不算"
	echo 
	echo -e "${cyan} 注意：${red}数据盘应保有足够大的空间执行打包操作，空间不够大的不适合这个脚本。"
	echo
	echo -e "${red} 备份的数据多则备份时间长，备份中不要按回车，请耐心等待"
  echo
	echo -e "${cyan} 第一次执行请直接 ${red}按1${none} 打包不成功重试。"
	echo
	echo -e "${cyan} 打包成功，但是因为种种原因没能上传成功请按 ${red}2${none}"
	echo
	read -p "$(echo -e "${red} 确定上面的都读过了，请选择数字: ${none}")" _opt
	echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
      1)
        pack_file
        rename_file
        remote_file
        ;;
      2)
        get_file_name
        remote_file
        ;;
    esac
  fi
}

#打包文件
pack_file(){
  read -rp "$(echo -e "请输入要打包文件的起始时间如 2022-01-01 :")" starttime
  read -rp "$(echo -e "请输入要打包文件的结束时间如 2023-01-01 :")" endtime
	find  /data/ /home/ ! -name '.*' -a ! -regex '.*/\.[^/]*/.*' -type f -print0 -newermt  $starttime ! -newermt $endtime | xargs -0 tar -czPf /data/test.tar.gz
  echo
	echo -e "已经打包好了，在/data/下，目前叫test.tar.gz"
}
#重命名文件
rename_file(){
  echo
	echo -e "${cyan} 接下来我们将给你即将打包的文件取个名字，比如：张三"
	echo
	echo -e "${cyan} 建议取自己的名字，但不要跟其他人的名称重复,尤其不要取111,222之类的名"
	echo
	echo -e "${red} 切换好你的输入法"
	echo
	read -p "$(echo -e "请输入你的文件名:${none}")" name
	echo
	echo -e "这个文件将被改为：${red}${name}.tar.gz ${none}，按任意键继续进行操作:"
  sleep 10
	echo
  char=`get_pause`
	echo
	mv /data/test.tar.gz /data/$name.tar.gz
	chmod 755 /data/$name.tar.gz
  echo
	echo -e "已经重命名好了，此文件名为：${red}${name}.tar.gz${none}"
}
#推到远程ftp服务器
remote_file(){
  echo
	echo -e "现在即将把这个文件传到ftp服务器上去"
	echo
	echo -e "比如ftp目录为文件夹${red}upload/2021${none}"
	echo
	echo -e "${cyan} 为了安全此脚本内不内置服务器密码，需要自己输入一下"
	echo
	echo -e "${cyan} 上传的文件大则上传时间长，请耐心等待 ${none}"
	echo
	echo -e "了解后按任意键继续进行操作:"
	echo
  char=`get_pause`
	echo
  echo
  read -rp "$(echo -e "请输入服务器IP地址如 192.168.210.5 ")" addr
	echo
  read -rp "$(echo -e "请输入服务器端地址如 /ftpdata/upload/2021/ ")" addr
  echo
	echo -e "请输入服务器密码:"
	echo
  #scp /data/$name.tar.gz  root@192.168.210.5:/ftpdata/upload/2021/
	scp /data/$name.tar.gz  root$addr:$addr_pwd
	echo
	echo -e " 已经上传好了，请打开左下角开始菜单，找到FileZilla这个FTP软件查看"
	echo
	rm -rif /data/$name.tar.gz
  echo
}
#获取文件名
get_file_name(){
	echo
	echo -e "${cyan} 比如说你的数据盘下的文件为：${red}张三.tar.gz${none}${cyan}，则直接输入：${red}张三${none}"
	echo
	read -p "$(echo -e " 请输入文件名：")" name
	echo
	echo -e " 要上传的文件名为：${red}${name}.tar.gz ${none}，确定则按任意键继续进行操作:"
	echo
  char=`get_pause`
	echo
}

#deb下载--总
download_deb() {
  clear
  downdeb_tmp="/var/cache/apt/archives/"
  downdeb_tmp_file="/var/cache/apt/archives/$download_flag.deb"

  if [ $download_flag == "dfonts" ]; then
    if [ $sys_str == "mips64" ]; then
      echo -e "$red 安装字体管理器--针对每个ttf文件只能单独安装$none \n"
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/fonts/font_3.16.2-3_mips64el.deb"
    elif [ $sys_str == "aarch64" ]; then
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/fonts/font_3.16.2-3_arm64.deb"
    elif [ $sys_str == "x86_64" ]; then
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/fonts/font_3.16.2-3_amd64.deb"
    else
      echo -e "暂不支持" && exit 1
    fi
  elif [ $download_flag == "todesk" ]; then
    echo -e "$red todesk不支持MIPS架构$none \n"
    if [ $sys_str == "aarch64" ]; then
      downdeb_link="https://newdl.todesk.com/linux/todesk-v4.3.1.0-arm64.deb"
    elif [ $sys_str == "x86_64" ]; then
      downdeb_link="https://newdl.todesk.com/linux/todesk-v4.3.1.0-amd64.deb"
    else
      echo -e "暂不支持" && exit 1
    fi
  elif [ $download_flag == "sunlogin" ]; then
    if [ $sys_str == "mips64" ]; then
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_mips.deb"
    elif [ $sys_str == "aarch64" ]; then
      if [ $cpu_name == "" ];then
        downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/11.x/sunloginclient_11.0.0.36662_arm64_kirin990_1228.deb"
      elif [ $cpu_name == "HUAWEI Kirin 9006C" ]; then
        downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/11.x/sunloginclient_11.0.0.36662_arm64_kirin9a0_20220221.deb"
      else
        downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_arm64.deb"
      fi
    elif [ $sys_str == "x86_64" ]; then
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_x86_64.deb"
    else
      echo -e "暂不支持" && exit 1
    fi
  elif [ $download_flag == "wx_2.1.4" ]; then
    if [ $sys_str == "x86_64" ]; then
      downdeb_link="http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/weixin_2.1.4-1_amd64.deb"
    elif [ $sys_str == "aarch64" ]; then
      downdeb_link="http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1/pool/all/weixin_2.1.4-1_arm64.deb"
    else
      echo -e "暂不支持" && exit 1
    fi
  elif [ $download_flag == "tencent_metting" ]; then
    if [ $sys_str == "x86_64" ]; then
      downdeb_link="https://updatecdn.meeting.qq.com/cos/9b74d4127a16a011db8cb6300fa5fbc9/TencentMeeting_0300000000_3.11.0.402_x86_64_default.publish.deb"
    elif [ $sys_str == "aarch64" ]; then
      downdeb_link="https://updatecdn.meeting.qq.com/cos/ce5d25cc8e8aae8ddd19295bc3b00d5e/TencentMeeting_0300000000_3.11.0.402_arm64_default.publish.deb"
    else
      echo -e "暂不支持" && exit 1
    fi
  elif [ $download_flag == "tencent_linuxqq" ]; then
    if [ $sys_str == "x86_64" ]; then
      downdeb_link="https://dldir1.qq.com/qqfile/qq/QQNT/c6032ac7/linuxqq_3.1.0-9332_amd64.deb"
    elif [ $sys_str == "aarch64" ]; then
      downdeb_link="https://dldir1.qq.com/qqfile/qq/QQNT/c6032ac7/linuxqq_3.1.0-9332_arm64.deb"
    elif [ $sys_str == "loongarch64" ]; then
      downdeb_link="https://dldir1.qq.com/qqfile/qq/QQNT/c6032ac7/linuxqq_3.1.0-9332_loong64.deb"
    else
      echo -e "暂不支持" && exit 1
    fi
  else
    echo -e "暂不支持" && exit 1
  fi

  if ! wget --no-check-certificate -O "$downdeb_tmp_file" $downdeb_link; then
    echo -e "$red 下载文件失败..$none" && exit 1
  fi

  cd $downdeb_tmp || exit
  chmod 777 $download_flag.deb
  dpkg -i $download_flag.deb

  if [ $download_flag == "dfonts" ]; then
    echo -e "$red 应该是下载并安装成功了，右键ttf文件在字体查看器中打开，右上角有安装按钮。$none \n"
  elif [ $download_flag == "todesk" ]; then
    xhost +
    echo
    echo -e "$red 应该是下载并安装成功了$none \n"
    echo
    echo -e "$red 在左下角开始菜单--所有程序里打开todesk$none \n"
    echo
    echo -e "也可以尝试按任意键直接打开todesk，但是某些版本可能连不上，需重启电脑再打开"
    echo
    echo -e "按ctrl + c退出"
    echo
    char=$(get_pause)
    su $this_user & /opt/todesk/bin/ToDesk
  elif [ $download_flag == "sunlogin" ]; then
    xhost +
    echo
    echo -e "$red 应该是下载并安装成功了$none \n"
    echo
    echo -e "$red 在左下角开始菜单--所有程序里打开向日葵$none \n"
    echo
    # echo -e "也可以尝试按任意键直接打开向日葵，但是某些版本可能连不上，需重启电脑再打开"
    # echo
    # echo -e "按ctrl + c退出"
    # echo
    # char=$(get_pause)
    # /usr/local/sunlogin/bin/sunloginclient
  elif [ $download_flag == "wx_2.1.4" ]; then
    echo -e "$red 微信2.1.4版已安装$none \n"
  elif [ $download_flag == "tencent_metting" ]; then
    echo
    echo -e "$red 应该是下载并安装成功了$none \n"
    echo
    echo -e "$red 在左下角开始菜单--所有程序里打开腾讯会议$none \n"
  elif [ $download_flag == "tencent_linuxqq" ]; then
    echo
    echo -e "$red 应该是下载并安装成功了$none \n"
    echo
    echo -e "$red 在左下角开始菜单--所有程序里打开QQ$none \n"
  fi
}

#zip下载-总
download_zip() {
  clear
  downzip_tmp="/tmp/$download_flag/"
  downzip_tmp_file="/tmp/$download_flag/$download_flag.zip"
  mkdir -p $downzip_tmp
  
  if [ $download_flag == "wx_mips_depend" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Tencent/Wechat/Mips/wechat-mips2.0-depend.zip"
    fi
  elif [ $download_flag == "act_v10_0710" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_0710.zip"
    elif [ $sys_str == "aarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_0710.zip"
    fi
  elif [ $download_flag == "act_v10_0710_2" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_0710_2.zip"
    elif [ $sys_str == "aarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_0710_2.zip"
    fi
  elif [ $download_flag == "act_v10_1026" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_1026.zip"
    elif [ $sys_str == "aarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_1026.zip"
    fi
  elif [ $download_flag == "act_v10_1026_2" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_1026_2.zip"
    elif [ $sys_str == "aarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_1026_2.zip"
    fi
  elif [ $download_flag == "act_v10_2107" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_mips_2107.zip"
    elif [ $sys_str == "aarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_arm_2107.zip"
    elif [ $sys_str == "x86_64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_x86_2107.zip"
    fi
  elif [ $download_flag == "act_v10_2203" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_V10_mips_2203.zip"
    elif [ $sys_str == "aarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_V10_arm_2203.zip"
    elif [ $sys_str == "x86_64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_v10_x86_2203.zip"
    fi
  elif [ $download_flag == "act_v10sp1_2107" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_mips_2107.zip"
    elif [ $sys_str == "aarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_arm_2107.zip"
    elif [ $sys_str == "x86_64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_x86_2107.zip"
    fi
  elif [ $download_flag == "act_v10sp1_2203" ]; then
    if [ $sys_str == "mips64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_mips_2203.zip"
    elif [ $sys_str == "aarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_arm_2203.zip"
    elif [ $sys_str == "x86_64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_x86_2203.zip"
    elif [ $sys_str == "loongarch64" ]; then
      downzip_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_loongarch_2203.zip"
    fi
  elif [ $download_flag == "kelu_xuke" ]; then
    if [ $sys_str == "mips64" ]; then
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kelu/xuke_mips.zip"
    elif [ $sys_str == "aarch64" ]; then
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kelu/xuke_arm.zip"
    elif [ $sys_str == "x86_64" ]; then
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kelu/xuke_x86.zip"
    elif [ $sys_str == "loongarch64" ]; then
      downdeb_link="https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kelu/xuke_loongarch64.zip"
    fi
  else
    echo -e "暂不支持" && exit 1
  fi

  if ! wget --no-check-certificate -O "$downzip_tmp_file" $downzip_link; then
    echo -e "$red 下载文件失败..$none" && exit 1
  fi

  cd $downzip_tmp || exit
  unzip $download_flag.zip

  if [ $download_flag == "wx_mips_depend" || $download_flag == "kelu_xuke" ]; then
    chmod 777 *.deb
    dpkg -i *.deb
    dpkg -i *.deb
  elif [ $act_flag == "activation" ]; then
    cp $downzip_tmp/.kyinfo $downzip_tmp/LICENSE /etc/
    echo -e "$red 应该是修改完了，关闭之前的激活页面，重新打开激活页面激活一下吧。$none \n"
  fi
}

#程序入口
menu() {
  clear
  while :; do
    echo
    echo "......................系统环境异常修复........................."
    echo
    echo "..........我的电脑右键属性--FT2000属于ARM、3A4000属于mips........"
    echo
    echo -e "$yellow 0. $none按0退出"
    echo
    echo -e "$yellow 1. $none查看系统信息--系统基本信息、实时网速等"
    echo
    echo -e "$yellow 2. $none修复系统问题--激活问题、桌面无状态栏、图标等"
    echo
    echo -e "$yellow 3. $none修复软件源、软件少、软件无法安装、软件商店报错等问题"
    echo
    echo -e "$yellow 4. $none软件相关--微信、远程、字体、金山等"
    echo
    echo -e "$yellow 5. $none查找文件或安装包"
    echo
    echo -e "$yellow 6. $none打印机相关"
    echo
    echo -e "$yellow 7. $none上传文件到FTP"
    echo
    echo -e "温馨提示...如果你不想执行选项...按$yellow 0 $none或者 $yellow Ctrl + C $none即可退出"
    echo
    read -rp "$(echo -e "请选择菜单 [${green}0-8$none]:")" choose
    if [[ -z $choose ]]; then
      exit 1
    else
      case $choose in
      0)
        clear
        exit
        break
        ;;
      1)
        system_message
        break
        ;;
      2)
        system_repair
        break
        ;;
      3)
        software_repair
        break
        ;;
      4)
        software
        break
        ;;
      5)
        find_files
        break
        ;;
      6)
        install_cups
        break
        ;;
      7)
        up_to_ftp
        break
        ;;
      esac
    fi
  done
}
args=$1
[ -z $1 ] && args="menu"
case $args in
menu)
  menu
  ;;
esac
